﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace Billing
{
    public class KeyboardSwitcher
    {
        private static string systemDefaultCulture;

        public static void SaveSystemDefaultCulture()
        {
            systemDefaultCulture = InputLanguage.CurrentInputLanguage.Culture.Name;
        }

        public static void RestoreSystemDefaultCulture()
        {
            if (!string.IsNullOrEmpty(systemDefaultCulture))
                SwitchKeyboardLayoutToCulture(systemDefaultCulture, true);
        }

        public static void SwitchKeyboardLayoutToKA(bool doNotThrowException)
        {
            SwitchKeyboardLayoutToCulture("ka-ge", doNotThrowException);
        }

        public static void SwitchKeyboardLayoutToEN(bool doNotThrowException)
        {
            SwitchKeyboardLayoutToCulture("en", doNotThrowException);
        }

        public static void SwitchKeyboardLayoutToCulture(string cultureName, bool doNotThrowException)
        {
            try
            {
                InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new System.Globalization.CultureInfo(cultureName));
            }
            catch (Exception x)
            {
                if (!doNotThrowException)
                    throw x;
            }
        }

        public static void SwitchKeyboardLayoutBetween(string cultureNameA, string cultureNameB, bool doNotThrowException)
        {
            if (InputLanguage.CurrentInputLanguage.Culture.Name.Equals(cultureNameA))
            {
                SwitchKeyboardLayoutToCulture(cultureNameB, true);
            }
            else
            {
                SwitchKeyboardLayoutToCulture(cultureNameA, true);
            }
        }
    }
}
